package ahblue.cn.tanzi.ui.person.pay;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.tencent.mm.opensdk.modelpay.PayReq;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.TanZiApplication;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/** http://ask.dcloud.net.cn/question/11439
import static ahblue.cn.tanzi.TanZiApplication.WXAPPKEY;

/**
 * @author pink-jackstraw
 * @date 2018/12/07
 * @describe
 */
public class PayDialog extends BDialog {
    private WAPayNode mModel;
    @BindView(R.id.ivzfb)
    ImageView ivzfb;
    @BindView(R.id.ivwx)
    ImageView ivwx;
    private Activity mContext;
    @BindView(R.id.root)
    RelativeLayout root;
    private int layoutId = R.layout.dialog_pay_select;
    private String pay = "wx";

    public PayDialog(Activity context, WAPayNode b) {
        super(context);
        this.mContext = context;
        this.mModel = b;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId);
        ButterKnife.bind(this);
    }

    @Override
    public boolean isCancelable(boolean b) {
        return false;
    }

    @Override
    public int setGravity(int gravity) {
        return Gravity.BOTTOM;
    }

    @Override
    public int setPadWidth(float width) {
        return 0;
    }

    @Override
    public int setPadHeight(float height) {
        return 0;
    }

    @Override
    public View getRootView() {
        return root;
    }

    private View.OnClickListener clickListener;

    public void setOnclick(View.OnClickListener clickListener) {
        this.clickListener = clickListener;
    }

    private void pay(String channel) {

        PayReq request = new PayReq();
        request.appId = mModel.getAppid();
        request.partnerId = mModel.getPartnerid();
        request.prepayId = mModel.getPrepayid();
        request.packageValue =mModel.getPackageX();
        request.nonceStr = mModel.getNoncestr();
        request.timeStamp = mModel.getTimestamp();
        request.sign = mModel.getSign();
        TanZiApplication.api.sendReq(request);

    }

    @OnClick({R.id.tvcancle, R.id.llalp, R.id.llwx, R.id.pay, R.id.root})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvcancle:
                dismiss();
                break;
            case R.id.llalp:
                ivzfb.setBackground(getContext().getResources().getDrawable(R.drawable.option_select));
                ivwx.setBackground(getContext().getResources().getDrawable(R.drawable.book_check_no_select));
                pay = "alipay";
                break;
            case R.id.llwx:
                ivwx.setBackground(getContext().getResources().getDrawable(R.drawable.option_select));
                ivzfb.setBackground(getContext().getResources().getDrawable(R.drawable.book_check_no_select));
                pay = "wx";
                break;
            case R.id.pay:
                pay(pay);
                dismiss();
                break;
            case R.id.root:
                dismiss();
                break;
        }
    }
}
